import login from '@/views/login'
import admin from '@/views/admin'

// 自动引入子路由
const moduleFn = require.context('./routes', false, /\.js$/i)
let routes = moduleFn.keys().reduce((perv, filepath) => {
  let module = moduleFn(filepath).default
  if (Array.isArray(module)) {
    perv.push(...module)
  } else {
    perv.push(module)
  }
  return perv
}, [])

// 注册主路由 主页面
export default [
  {
    path: '/login',
    name: 'login',
    component: login,
  },
  {
    path: '/',
    name: 'admin',
    component: admin,
    children: routes
  }
]
